package com.soft.face.controller;

import com.soft.face.config.system.ServerConfig;
import com.soft.face.config.system.SystemConfig;
import com.soft.face.global.R;
import com.soft.face.utils.file.FileUploadUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@Api(tags = "文件")
@RestController
@RequestMapping("file")
@AllArgsConstructor
public class FileController {

    private ServerConfig serverConfig;

    @PostMapping("upload")
    @ApiOperation(value = "文件上传")
    public R<?> upload(@RequestPart MultipartFile file) throws Exception {
        // 上传文件路径
        String filePath = SystemConfig.getUploadPath();
        return R.success(serverConfig.getUrl() + FileUploadUtils.upload(filePath, file));
    }

}
